//package com.itheima.springbootwebtlias.aspect;
//
//import com.itheima.springbootwebtlias.commons.CurrentHolder;
//import com.itheima.springbootwebtlias.mapper.OperateLogMapper;
//import com.itheima.springbootwebtlias.pojo.OperateLog;
//import com.itheima.springbootwebtlias.util.JwtUtils;
//import io.jsonwebtoken.Claims;
//import jakarta.servlet.http.HttpServletRequest;
//import jakarta.servlet.http.HttpServletResponse;
//import lombok.extern.slf4j.Slf4j;
//import org.aspectj.lang.ProceedingJoinPoint;
//import org.aspectj.lang.annotation.Around;
//import org.aspectj.lang.annotation.Aspect;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Component;
//
//import java.time.LocalDateTime;
//import java.util.Arrays;
//
///*
//记录操作日志的切面类
// */
//@Slf4j
//@Aspect
//@Component
//public class OperationLogAspect {
//
//    @Autowired
//    private OperateLogMapper operateLogMapper;
//
//    @Autowired
//    private HttpServletRequest request;
//
//    public OperationLogAspect(OperateLogMapper operateLogMapper) {
//        this.operateLogMapper = operateLogMapper;
//    }
//
//    //切入点表达式 execution + annotation
//    //通知类型:环绕通知
//    @Around("execution(* com.itheima.springbootwebtlias.service.*Service.*(..)) && @annotation(com.itheima.springbootwebtlias.anno.LogOperation)")
//    public Object recordOperationLog(ProceedingJoinPoint pjp) throws Throwable {
//        //1.记录操作日志，手机操作日记信息，添加到操作日志数据中
//        long start = System.currentTimeMillis();
//        Object result = pjp.proceed();
//        long end = System.currentTimeMillis();
//        long costTime = end - start;
//
//        //从请求头中的
//        String jwtToken = request.getHeader("token");
//        Claims datas = JwtUtils.parseJWT(jwtToken);
//        Integer id  = (Integer) datas.get("id");
//
//        //1.定义操作日志对象，手机操作日志信息
//        OperateLog operateLog = new OperateLog();
//        operateLog.setOperateTime(LocalDateTime.now()); //操作时间
//        operateLog.setOperateEmpId(CurrentHolder.getCurrentId()); //操作的员工Id 暂时跳过
//
//        operateLog.setClassName(pjp.getTarget().getClass().getName());//获取目标方法所属的类名称
//        operateLog.setMethodName(pjp.getSignature().getName()); //获取目标方法名称
//        operateLog.setMethodParams(Arrays.toString(pjp.getArgs())); //获取目标方法的参数列表
//        operateLog.setReturnValue(result+""); //获取目标方法的返回值
//        operateLog.setCostTime(costTime);
//
//
//        //2.调用操作日志的持久层接口，添加日志信息到操作日志表中
//        operateLogMapper.insert(operateLog);
//
//        return result;
//
//    }
//}
